#!/usr/bin/python
#coding = utf-8
import sys

person = '1'
result = {}
frienddic = {}

# for line in sys.stdin:
#     words = line.strip('\n').strip('\t')
#     words = words.split(',')
#     listre.append(words)


# size = len(listre)
# index = 0
# while index < size:




for line in sys.stdin:
    words = line.strip('\n').strip('\t')
    words = words.split(',')
    temp = words[1].split('#')
    friend = temp[0]
    same = temp[1]
    if person != words[0]:        
        output = person + ':'
        for line in frienddic:           
            if '0' in frienddic[line]:
                continue
            else:
                output = output + line + '(' + str(len(frienddic[line])) + ':['
                for word in frienddic[line]:
                    output = output + word +','
                output = output.strip(',')
                output = output + ']),'
        print(output.strip(','))
        frienddic.clear()
        result.clear()
        frienddic = {}
        result={}
        person = words[0]
        frienddic.setdefault(friend,[]).append(same)
        result[person]=frienddic
    else:        
        frienddic.setdefault(friend,[]).append(same)


output = person + ':'
for line in frienddic:           
    if '0' in frienddic[line]:
        temp = 0
        continue
    else:
        output = output + line + '(' + str(len(frienddic[line])) + ':['
        for word in frienddic[line]:
            output = output + word +','
        output = output.strip(',')
        output = output + ']),'
if temp==0:
    print(output.strip(',')+'\t')
        